package a_exception.c_throw;

//throw
public class ThrowDemo {
    //根据 索引找到数组中对应的元素
    public static int getElement(int[] arr,int index){
        //判断 下标是否越界
        if (index < 0 || index > arr.length - 1){
            //不在范围之内,也就是满足条件,也就是越界了,直接抛出异常
            throw new ArrayIndexOutOfBoundsException("越界了");
        }
        int ele = arr[index];
        return ele;
    }
}
